package com.alibaba.algo.config;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;

import java.util.Properties;

/**
 * @author : WangZhiPan
 * @date : 2021/10/12 11:04
 */
// ExamplePlugin.java
@Intercepts({@Signature(
        type = Executor.class,
        method = "updateById",
        args = {MappedStatement.class, Object.class})})
@Slf4j
public class MybatisPlugins implements Interceptor {
    private Properties properties = new Properties();

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        // implement pre processing if need
        log.info("invocation=={}", JSON.toJSONString(invocation));
        Object returnObject = invocation.proceed();
        // implement post processing if need
        return returnObject;
    }

    @Override
    public Object plugin(Object o) {
        return null;
    }

    @Override
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
}
